package com.qingke.Qiximybatis.command;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import com.qingke.Qiximybatis.business.Increase4;
import com.qingke.Qiximybatis.business.InforInvited13;
import com.qingke.Qiximybatis.business.Interest5;
import com.qingke.Qiximybatis.business.InvitationIn12;
import com.qingke.Qiximybatis.business.ListUser;
import com.qingke.Qiximybatis.business.ManyPersonal10;
import com.qingke.Qiximybatis.business.Personal9;
import com.qingke.Qiximybatis.business.SchoolSystem6;
import com.qingke.Qiximybatis.business.SelectBeauty8;
import com.qingke.Qiximybatis.business.SelectMan11;
import com.qingke.Qiximybatis.business.Update3;
import com.qingke.Qiximybatis.business.UpdateStudent7;
import com.qingke.Qiximybatis.sqlclass.MyUser;

public class UserCommandFactory extends SystemCommandFactory{
	
	private static Map<CommandCode,Class<?extends Command>> commandMap = new HashMap<>();
	
	static {
		commandMap.put(CommandCode.LISTUSER, ListUser.class);
		commandMap.put(CommandCode.UPDATE, Update3.class);
		commandMap.put(CommandCode.INCREASE, Increase4.class);
		commandMap.put(CommandCode.INTEREST_UPDATE, Interest5.class);
		commandMap.put(CommandCode.SCHOOLSYSTEM, SchoolSystem6.class);
		commandMap.put(CommandCode.UPDATESTUDENT, UpdateStudent7.class);
		commandMap.put(CommandCode.SELECT_BEAUTY, SelectBeauty8.class);
		commandMap.put(CommandCode.A_PERSONAL_INVITATION, Personal9.class);
		commandMap.put(CommandCode.MANY, ManyPersonal10.class);
		commandMap.put(CommandCode.SELECT_MAN, SelectMan11.class);
		commandMap.put(CommandCode.INVITATION_INFORMATION, InvitationIn12.class);
		commandMap.put(CommandCode.INFORMATION_TO_BE_INVITED, InforInvited13.class);
	}
	private MyUser user;
	
	
	public UserCommandFactory(MyUser user) {
		this.user = user;
	}
	
	@Override
	public Command buildCommand(CommandCode cmdCode) {
		Command command = null;
		
		Class<? extends Command> cmdClass = commandMap.get(cmdCode);
		
		if(cmdClass != null) {
			try {
				command = cmdClass.getConstructor(MyUser.class).newInstance(user);//创建构造方法，getConstructor, 
			} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
					| InvocationTargetException | NoSuchMethodException | SecurityException e) {
				e.printStackTrace();
			}
		}
		if(command == null) {
			command = super.buildCommand(cmdCode);
		}
		return command;
	}
	
}
